﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Moq;
using Ploeh.AutoFixture;

namespace Mocking
{
	public static class MockingExtensions
	{
		public static Mock<T> MockOf<T>(this IFixture fixture) where T : class
		{
			ConcreteMoqBuilder builder =
				fixture.Customizations.Where(c => c is ConcreteMoqBuilder)
				.FirstOrDefault() as ConcreteMoqBuilder;

			return (Mock<T>)builder.Mocks.Where(mocked => mocked.MockedType == typeof(T))
				.FirstOrDefault().Mock;
		}
	}
}
